home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Other Langs / Tickle-4.0 (tcl) / tcl / expecTerm / win.h < prev   
Encoding:
C/C++ Source or Header  |  1993-11-17  |  11.2 KB  |  457 lines  |  [TEXT/MPS ]

  1. /* win.h
  2. **************************************************************************** 
  3. expecTerm version 1.0 beta
  4. Mark Weissman
  5. Christopher Matheus
  6. Copyright 1992 by GTE Laboratories Incorporated.
  7.  
  8. Portions of this work are in the public domain.  Permission to use,
  9. copy, modify, and distribute this software and its documentation for
  10. any purpose and without fee is hereby granted, provided that the above
  11. copyright notice appear in all copies and that both the copyright
  12. notice and warranty disclaimer appear in supporting documentation, and
  13. that the names of GTE Laboratories or any of their entities not be
  14. used in advertising or publicity pertaining to distribution of the
  15. software without specific, written prior permission.
  16.  
  17. GTE disclaims all warranties with regard to this software, including
  18. all implied warranties of merchantability and fitness for a particular
  19. purpose, even if GTE Laboratories Incorporated knows about the
  20. purpose.  In no event shall GTE be liable for any special, indirect or
  21. consequential damages or any damages whatsoever resulting from loss of
  22. use, data or profits, whether in an action of contract, negligence or
  23. other tortuous action, arising out of or in connection with the use or
  24. performance of this software.
  25.  
  26. This code is based on and may include parts of Don Libes' expect code:
  27.   expect written by: Don Libes, NIST, 2/6/90
  28.   Design and implementation of expect was paid for by U.S. tax
  29.   dollars.  Therefore it is public domain.  However, the author and NIST
  30.   would appreciate credit if this program or parts of it are used.
  31. ******************************************************************************/
  32.  
  33. #ifndef _VTEM_HEADER
  34. #define _VTEM_HEADER
  35. #include <stdio.h>
  36. #include <signal.h>
  37. #include <time.h>
  38. #include <fcntl.h>
  39. #include <setjmp.h>
  40. #include <sys/types.h>
  41. #include <sys/time.h>
  42. #include <sys/stat.h>
  43. #include <sys/wait.h>
  44. #include "compat.h"
  45.  
  46. #define BITS7 '\177'
  47. #define NUL '\200'
  48.  
  49. #define BYTE7(X) ((X) & BITS7)
  50.  
  51.  
  52. #define FILEMESS(FILENAME,STRING) {    \
  53.   char buf[256];                       \
  54.   FILE *foo;                           \
  55.   if ((foo=fopen(FILENAME,"a")) > (FILE *)0) {     \
  56.     fprintf(foo,"%s",STRING);          \
  57.     fclose(foo);                       \
  58.   }                                    \
  59. }
  60.  
  61. #ifndef DEBUG
  62. #define DEBUG0(LEVEL,STR)                NULL
  63. #define DEBUG1(LEVEL,STR,ARG)            NULL
  64. #define DEBUG2(LEVEL,STR,A1,A2)          NULL
  65. #define DEBUG3(LEVEL,STR,A1,A2,A3)       NULL
  66. #define DEBUG4(LEVEL,STR,A1,A2,A3,A4)    NULL
  67. #define DEBUG5(LEVEL,STR,A1,A2,A3,A4,A5) NULL
  68. #else
  69. #define DEBUG0(LEVEL,STR)                {if(LEVEL<=DEBUG) FILEMESS(WLOG,(sprintf(buf,"%s" ## STR,indent),buf));}
  70. #define DEBUG1(LEVEL,STR,ARG)            {if(LEVEL<=DEBUG) FILEMESS(WLOG,(sprintf(buf,"%s" ## STR,indent,ARG),buf));}
  71. #define DEBUG2(LEVEL,STR,A1,A2)          {if(LEVEL<=DEBUG) FILEMESS(WLOG,(sprintf(buf,"%s" ## STR,indent,A1,A2),buf));}
  72. #define DEBUG3(LEVEL,STR,A1,A2,A3)       {if(LEVEL<=DEBUG) FILEMESS(WLOG,(sprintf(buf,"%s" ## STR,indent,A1,A2,A3),buf));}
  73. #define DEBUG4(LEVEL,STR,A1,A2,A3,A4)    {if(LEVEL<=DEBUG) FILEMESS(WLOG,(sprintf(buf,"%s" ## STR,indent,A1,A2,A3,A4),buf));}
  74. #define DEBUG4(LEVEL,STR,A1,A2,A3,A4)    {if(LEVEL<=DEBUG) FILEMESS(WLOG,(sprintf(buf,"%s" ## STR,indent,A1,A2,A3,A4),buf));}
  75. #define DEBUG5(LEVEL,STR,A1,A2,A3,A4,A5) {if(LEVEL<=DEBUG) FILEMESS(WLOG,(sprintf(buf,"%s" ## STR,indent,A1,A2,A3,A4,A5),buf));}
  76. #endif
  77.  
  78. #if defined(NLS)
  79. /* There appears to be a bug in setting margins */
  80. #define TMARG(W) (W)->win->_tmarg
  81. #define BMARG(W) (W)->win->_bmarg
  82. #define wsetscroll(W,MT,MB) wsetscrreg(W->win,MT,MB)
  83. #else
  84. #define TMARG(W) (W)->tmarg
  85. #define BMARG(W) (W)->bmarg
  86. #define wsetscroll(W,MT,MB) (TMARG(W)=MT,BMARG(W)=MB)
  87. #endif
  88.  
  89. #define ECHOP_DEFAULT "0"
  90. #define BREAKS_DEFAULT "0"
  91. #define TABSPACEP_DEFAULT "0"
  92. #define CRNLP_DEFAULT "0"
  93.  
  94. #define RETRY 1
  95. #define WLOG  "debug.log"
  96. #define FAILURE -1
  97. #ifndef ERR
  98. #define ERR (-1)
  99. #endif
  100. #define STOPPED -1L
  101.  
  102. #define MAXSESSION 17
  103.  
  104. #define BEL (7)
  105. #define SI (15)
  106. #define ESC ('\033')
  107. #define MAXTERMARG (10)
  108. #define MAXTERMVAR (26)
  109. #define TERMESC '@'
  110.  
  111. #define MAXEBITS 64
  112.  
  113. #define XMAX 256
  114. #define XMIN 0
  115. #define YMAX 128
  116. #define YMIN 0
  117.  
  118. #define WIN_UNGET_MAX     (XMAX)
  119. #define WIN_COOKED_MAX     (XMAX)
  120. #define WIN_TABS_MAX    (XMAX)
  121. #define WIN_RAW_MAX     (4028)
  122. #define WIN_EXP_MAX     (4028)
  123. #define WIN_SESSION_MAX (64)
  124.  
  125. #define WIN_DEFAULT_WINBAR ((char *)-1)
  126.  
  127. typedef struct TermTabStruct {
  128.     short int termtab;
  129.     char *type;
  130.     char Local;
  131.     char InsertMode;
  132.     char *str_acsc;
  133.     char *str_apstr;
  134.     char *str_batt1;
  135.     char *str_batt2;
  136.     char *str_box1;
  137.     char *str_box2;
  138.     char *str_colb0;
  139.     char *str_colb1;
  140.     char *str_colb2;
  141.     char *str_colb3;
  142.     char *str_colb4;
  143.     char *str_colb5;
  144.     char *str_colb6;
  145.     char *str_colb7;
  146.     char *str_colf0;
  147.     char *str_colf1;
  148.     char *str_colf2;
  149.     char *str_colf3;
  150.     char *str_colf4;
  151.     char *str_colf5;
  152.     char *str_colf6;
  153.     char *str_colf7;
  154.     char *str_if;
  155.     char *str_ip;
  156.     char *str_iprog;
  157.     char *str_kBEG;
  158.     char *str_kCAN;
  159.     char *str_kCMD;
  160.     char *str_kCPY;
  161.     char *str_kCRT;
  162.     char *str_kDC;
  163.     char *str_kDL;
  164.     char *str_kEND;
  165.     char *str_kEOL;
  166.     char *str_kEXT;
  167.     char *str_kFND;
  168.     char *str_kHLP;
  169.     char *str_kHOM;
  170.     char *str_kIC;
  171.     char *str_kLFT;
  172.     char *str_kMOV;
  173.     char *str_kMSG;
  174.     char *str_kNXT;
  175.     char *str_kOPT;
  176.     char *str_kPRT;
  177.     char *str_kPRV;
  178.     char *str_kRDO;
  179.     char *str_kRES;
  180.     char *str_kRIT;
  181.     char *str_kRPL;
  182.     char *str_kSAV;
  183.     char *str_kSPD;
  184.     char *str_kUND;
  185.     char *str_ka1;
  186.     char *str_ka3;
  187.     char *str_kb2;
  188.     char *str_kbeg;
  189.     char *str_kbs;
  190.     char *str_kbtab;
  191.     char *str_kc1;
  192.     char *str_kc3;
  193.     char *str_kcan;
  194.     char *str_kcbt;
  195.     char *str_kclo;
  196.     char *str_kclr;
  197.     char *str_kcmd;
  198.     char *str_kcpn;
  199.     char *str_kcpy;
  200.     char *str_kcrt;
  201.     char *str_kctab;
  202.     char *str_kcub1;
  203.     char *str_kcud1;
  204.     char *str_kcuf1;
  205.     char *str_kcuu1;
  206.     char *str_kdch1;
  207.     char *str_kdl1;
  208.     char *str_kdo;
  209.     char *str_ked;
  210.     char *str_kel;
  211.     char *str_kend;
  212.     char *str_kent;
  213.     char *str_kext;
  214.     char *str_kf0;
  215.     char *str_kf1;
  216.     char *str_kf2;
  217.     char *str_kf3;
  218.     char *str_kf4;
  219.     char *str_kf5;
  220.     char *str_kf6;
  221.     char *str_kf7;
  222.     char *str_kf8;
  223.     char *str_kf9;
  224.     char *str_kf10;
  225.     char *str_kf11;
  226.     char *str_kf12;
  227.     char *str_kf13;
  228.     char *str_kf14;
  229.     char *str_kf15;
  230.     char *str_kf16;
  231.     char *str_kf17;
  232.     char *str_kf18;
  233.     char *str_kf19;
  234.     char *str_kf20;
  235.     char *str_kf21;
  236.     char *str_kf22;
  237.     char *str_kf23;
  238.     char *str_kf24;
  239.     char *str_kf25;
  240.     char *str_kf26;
  241.     char *str_kf27;
  242.     char *str_kf28;
  243.     char *str_kf29;
  244.     char *str_kf30;
  245.     char *str_kf31;
  246.     char *str_kf32;
  247.     char *str_kf33;
  248.     char *str_kf34;
  249.     char *str_kf35;
  250.     char *str_kf36;
  251.     char *str_kf37;
  252.     char *str_kf38;
  253.     char *str_kf39;
  254.     char *str_kf40;
  255.     char *str_kf41;
  256.     char *str_kf42;
  257.     char *str_kf43;
  258.     char *str_kf44;
  259.     char *str_kf45;
  260.     char *str_kf46;
  261.     char *str_kf47;
  262.     char *str_kf48;
  263.     char *str_kf49;
  264.     char *str_kf50;
  265.     char *str_kf51;
  266.     char *str_kf52;
  267.     char *str_kf53;
  268.     char *str_kf54;
  269.     char *str_kf55;
  270.     char *str_kf56;
  271.     char *str_kf57;
  272.     char *str_kf58;
  273.     char *str_kf59;
  274.     char *str_kf60;
  275.     char *str_kf61;
  276.     char *str_kf62;
  277.     char *str_kf63;
  278.     char *str_kfnd;
  279.     char *str_khlp;
  280.     char *str_khome;
  281.     char *str_khts;
  282.     char *str_kich1;
  283.     char *str_kil1;
  284.     char *str_kind;
  285.     char *str_kll;
  286.     char *str_kmov;
  287.     char *str_kmpf1;
  288.     char *str_kmpf2;
  289.     char *str_kmpf3;
  290.     char *str_kmpf4;
  291.     char *str_kmpf5;
  292.     char *str_kmpt1;
  293.     char *str_kmpt2;
  294.     char *str_kmpt3;
  295.     char *str_kmpt4;
  296.     char *str_kmpt5;
  297.     char *str_kmrk;
  298.     char *str_kmsg;
  299.     char *str_knl;
  300.     char *str_knp;
  301.     char *str_knpn;
  302.     char *str_knxt;
  303.     char *str_kopn;
  304.     char *str_kopt;
  305.     char *str_kpcmd;
  306.     char *str_kpp;
  307.     char *str_kppn;
  308.     char *str_kpquit;
  309.     char *str_kprt;
  310.     char *str_kprv;
  311.     char *str_krdo;
  312.     char *str_kref;
  313.     char *str_kres;
  314.     char *str_krfr;
  315.     char *str_kri;
  316.     char *str_krmir;
  317.     char *str_krpl;
  318.     char *str_krst;
  319.     char *str_ksav;
  320.     char *str_kscl;
  321.     char *str_kscr;
  322.     char *str_kslt;
  323.     char *str_kspd;
  324.     char *str_ktab;
  325.     char *str_ktbc;
  326.     char *str_kund;
  327.     char *str_lf0;
  328.     char *str_lf10;
  329.     char *str_lf1;
  330.     char *str_lf2;
  331.     char *str_lf3;
  332.     char *str_lf4;
  333.     char *str_lf5;
  334.     char *str_lf6;
  335.     char *str_lf7;
  336.     char *str_lf8;
  337.     char *str_lf9;
  338.     char *str_pad;
  339.     char *str_rf;
  340.     char *str_rmp;
  341.     char *str_use;
  342.     char *str_xoffc;
  343.     char *str_xonc;
  344.     char bool_am;
  345.     char bool_bw;
  346.     char bool_chts;
  347.     char bool_cmdch;
  348.     char bool_da;
  349.     char bool_db;
  350.     char bool_eo;
  351.     char bool_eslok;
  352.     char bool_gn;
  353.     char bool_hc;
  354.     char bool_hpAutoKbdLock;
  355.     char bool_hpAutoLinefeed;
  356.     char bool_hpAutoTerm;
  357.     char bool_hpBlockMode;
  358.     char bool_hpCapsLock;
  359.     char bool_hpClearTerm;
  360.     char bool_hpDispFuns;
  361.     char bool_hpFormatMode;
  362.     char bool_hpInhibitDC2;
  363.     char bool_hpInhibitEOLWrap;
  364.     char bool_hpInhibitHandshake;
  365.     char bool_hpKbdLock;
  366.     char bool_hpKeys;
  367.     char bool_hpMemLock;
  368.     char bool_hpPageMode;
  369.     char bool_hpSPOW;
  370.     char bool_hpTransmitFuns;
  371.     char bool_hs;
  372.     char bool_hz;
  373.     char bool_in;
  374.     char bool_km;
  375.     char bool_labels;
  376.     char bool_mc5i;
  377.     char bool_mir;
  378.     char bool_mrcup;
  379.     char bool_msgr;
  380.     char bool_npc;
  381.     char bool_nrrmc;
  382.     char bool_nxon;
  383.     char bool_os;
  384.     char bool_ul;
  385.     char bool_xenl;
  386.     char bool_xhp;
  387.     char bool_xon;
  388.     char bool_xsb;
  389.     char bool_xt;
  390.     int int_cols;
  391.     int int_it;
  392.     int int_lh;
  393.     int int_lines;
  394.     int int_lm;
  395.     int int_lw;
  396.     int int_nlab;
  397.     int int_pb;
  398.     int int_vt;
  399.     int int_wsl;
  400.     int int_xmc;
  401.   } TermTab;
  402.  
  403. /* some definitions for event lines to check */
  404. typedef char *NAME;
  405. typedef void (*FPTR)();
  406. typedef int (*IFPTR)();
  407. typedef short Bool;
  408. typedef int PID, GID, FileDesc;
  409. typedef struct SessionStruct {
  410. /*  WINDOW     *win; */
  411.   struct _win_st *win;
  412.   FileDesc    fd;
  413.   FILE        *outp, *inp; 
  414.   PID         pid;
  415.   short     tabs[WIN_TABS_MAX], tmarg, bmarg, rmarg, lmarg;
  416.   long         save_x, save_y, num, x, y, rows, columns;
  417.   Bool        save_blink, save_bold, save_reverse, save_underline;
  418.   Bool         wrap, input_p, input_cached_p, dribble_p;
  419.   Bool        echop, crnlp, tabspacep, breaksp;
  420.   char        *raw_log_filename, *cooked_log_filename;
  421.   FILE        *raw_log, *cooked_log;
  422.   TermTab    *term, *termOriginal;
  423.   long        cookedIndex;
  424.   char        *rawBuff; /* Read Raw Into Buf */
  425.   long        rawIndex, rawEnd, rawMax;
  426.   long        expIndex;
  427.   struct {
  428.    long minrow, maxrow, mincol, maxcol;
  429.   } pad;
  430. } SESSION;
  431.  
  432. extern long MaxSession;
  433. extern long WinbarP;
  434. extern int loguser; /* was QuietP; */
  435. extern char charyx();
  436. extern char Buffer[];
  437. extern char *indent;
  438. extern long InitScr, ChildDiedP;
  439. extern long winbar();
  440. extern SESSION *CurrSession, *Sessions[];
  441. extern char *ExpectLogDir;
  442. extern char *ExpectDir;
  443. extern SESSION *Session;
  444. /** Runtime Routines **/
  445. extern DoDribble(), Undribble();
  446. extern fatal();
  447. extern char *ScreenDumpContents();
  448. extern struct _win_st    *stdscr, *curscr;
  449. extern char *SetStatusLine();
  450. extern double TimevalToDouble(), TimeOfDay();
  451. extern struct timeval *DoubleToTimeval();
  452. extern int loguser;
  453. extern char *getenv();
  454. extern char *get_var();
  455. extern void do_reset();
  456. #endif
  457.